package com.coco.homework.rules;

import com.coco.homework.Context;
import com.coco.homework.RomanNumber;

public interface IRomanNumberRule {

	String CHAR_REPEAT_MORE = "Char:{0}  repeat more then {1} times ";
	
	int MAX_REPEAT_COUNT = 3;
	
	void exec(Context context);
	
	RomanNumber getCanHandlerNumber();

	default boolean repeatRuleCheck(String str, char c, int maxRepeatCount) {
		int index = 0;
		for (char ch : str.toCharArray()) {
			if (ch != c) {
				return true;
			}
			if (index++ == maxRepeatCount) {
				return false;
			}
		}
		return true;
	}
	
	default boolean notRepeatRuleCheck(String str, char c) {
		int index = 0;
		for (char ch : str.toCharArray()) {
			if (ch != c) {
				return true;
			}
			if (index == 1) {
				return false;
			}
		}
		return true;
	}
}
